package com.easywan.filter;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.easywan.core.DBConnection;
import com.easywan.pojo.IResult;
import com.easywan.pojo.IResultSupport;
import com.easywan.pojo.PageRow;

import net.sf.json.JSONObject;
/**
 * @author tangkang
 * 后台登录拦截
 */
public class LoginFilter implements Filter{
	Logger logger = Logger.getLogger(LoginFilter.class);
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		String url =  req.getRequestURI();
		logger.info("拦截地址"+url);
		if(url.replace("/", "").replace("\\", "").equals("login.html")){
			chain.doFilter(request, response);
		}else if(url.replace("/", "").replace("\\", "").equals("toLogin.html")){
			chain.doFilter(request, response);
		}else{
			Object manager = req.getSession().getAttribute("manager");
			if(manager == null)
				//response.getWriter().write("服务器500错误！");
				((HttpServletResponse)response).sendRedirect("/login.html");
			else{
				chain.doFilter(request, response);
			}
		}
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}
	
}
